package com.itheima.testlearn.test7;

import java.util.Random;

public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;

    String[] boyface = {"风流倜傥", "气宇轩昂", "相貌英俊", "五官端正", "相貌平平", "一塌糊涂", "面目狰狞"};
    String[] girlface = {"美轮美奂", "沉鱼落雁", "亭亭玉立", "身材姣好", "相貌平平", "相貌简陋", "惨不忍睹"};

    public Role() {

    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public Role(String name, int blood, char gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        setFace(gender);
    }


    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return blood
     */
    public int getBlood() {
        return blood;
    }

    /**
     * 设置
     *
     * @param blood
     */
    public void setBlood(int blood) {
        this.blood = blood;
    }

    public String toString() {
        return "Role{name = " + name + ", blood = " + blood + "}";
    }

    /**
     * 获取
     *
     * @return gender
     */
    public char getGender() {
        return gender;
    }

    /**
     * 设置
     *
     * @param gender
     */
    public void setGender(char gender) {
        this.gender = gender;
    }

    /**
     * 获取
     *
     * @return face
     */
    public String getFace() {
        return face;
    }

    /**
     * 设置
     *
     * @param
     */
    public void setFace(char gender) {

        //长相随机
        Random r = new Random();
        if (gender == '男') {
            int index = r.nextInt(boyface.length);
            this.face = boyface[index];
        } else if (gender == '女') {
            int index = r.nextInt(girlface.length);
            this.face = girlface[index];
        } else {
            this.face = "面目狰狞";
        }
    }

    //定义一个方法用于攻击别人
    public void attack(Role role) {
        //计算造成的伤害 1~20
        Random r = new Random();
        int hurt = r.nextInt(20) + 1;

        //修改挨揍人的血量
        int remainblood = role.getBlood() - hurt;
        remainblood = remainblood < 0 ? 0 : remainblood;
        //修改一下挨揍人的血量
        role.setBlood(remainblood);

        System.out.println(this.getFace()+"的"+this.getName() + "举起拳头,打了" +role.getFace()+"的"+ role.getName() + "一拳，" +
                "造成" + hurt + "点伤害，" + role.getName() + "还剩下" + remainblood + "点血");

    }

    public void showRoleInfo() {
        System.out.println("姓名为：" + getName());
        System.out.println("血量为：" + getBlood());
        System.out.println("性别为：" + getGender());
        System.out.println("长相为：" + getFace());
    }


}
